package demoMod.nanaki.patches.events.shrines;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.shrines.AccursedBlacksmith;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.UpgradeShineEffect;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.tempCards.FurnaceForging;
import demoMod.nanaki.characters.NanakiCharacter;

public class AccursedBlacksmithPatch {
    public static final String ID = NanakiMod.makeID("Accursed Blacksmith");
    private static final EventStrings eventStrings = CardCrawlGame.languagePack.getEventString(ID);
    public static final String NAME = eventStrings.NAME;
    public static final String[] DESCRIPTIONS = eventStrings.DESCRIPTIONS;
    public static final String[] OPTIONS = eventStrings.OPTIONS;

    @SpirePatch(
            clz = AccursedBlacksmith.class,
            method = SpirePatch.CONSTRUCTOR
    )
    public static class PatchConstructor {
        public static void Postfix(AccursedBlacksmith event) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                event.imageEventText.updateDialogOption(0, OPTIONS[0], new FurnaceForging());
            }
        }
    }

    @SpirePatch(
            clz = AccursedBlacksmith.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(AccursedBlacksmith event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int screenNum = ReflectionHacks.getPrivate(event, AccursedBlacksmith.class, "screenNum");
                if (screenNum == 0 && buttonPressed == 0) {
                    event.imageEventText.updateBodyText(DESCRIPTIONS[1]);
                    AbstractDungeon.topLevelEffects.add(new UpgradeShineEffect((float)Settings.WIDTH / 2.0F, (float)Settings.HEIGHT / 2.0F));
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new FurnaceForging(), (float) Settings.WIDTH / 2.0F - 350.0F * Settings.xScale, (float)Settings.HEIGHT / 2.0F));
                    ReflectionHacks.setPrivate(event, AccursedBlacksmith.class, "screenNum", 2);
                    event.imageEventText.updateDialogOption(0, OPTIONS[2]);
                    event.imageEventText.clearRemainingOptions();
                    return SpireReturn.Return(null);
                }
            }
            return SpireReturn.Continue();
        }
    }
}
